import 'package:flutter/material.dart';

class MediaGridItem extends StatelessWidget {
  final Widget thumbnail;
  final bool isSelected;
  final int? selectOrder;
  final bool isDisabled;
  final bool isVideo;
  final String? duration;
  final VoidCallback? onTap;

  const MediaGridItem({
    Key? key,
    required this.thumbnail,
    this.isSelected = false,
    this.selectOrder,
    this.isDisabled = false,
    this.isVideo = false,
    this.duration,
    this.onTap,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return RepaintBoundary(
      child: AspectRatio(
        aspectRatio: 1.0,
        child: GestureDetector(
          onTap: onTap,
          child: Stack(
            children: [
              Positioned.fill(child: thumbnail),
              if (isDisabled)
                Positioned.fill(
                  child: Container(color: Colors.black54),
                ),
              if (isVideo && duration != null)
                Positioned(
                  bottom: 4,
                  left: 4,
                  child: Container(
                    padding: EdgeInsets.symmetric(horizontal: 4, vertical: 2),
                    decoration: BoxDecoration(
                      color: Colors.black54,
                      borderRadius: BorderRadius.circular(4),
                    ),
                    child: Text(
                      duration!,
                      style: TextStyle(
                        color: Colors.white,
                        fontSize: 10,
                        fontWeight: FontWeight.w500,
                      ),
                    ),
                  ),
                ),
              if (isSelected)
                Positioned(
                  top: 8,
                  right: 8,
                  child: Container(
                    width: 20,
                    height: 20,
                    decoration: BoxDecoration(
                      color: Colors.red,
                      shape: BoxShape.circle,
                    ),
                    child: Center(
                      child: Text(
                        '$selectOrder',
                        style: TextStyle(
                          color: Colors.white,
                          fontSize: 12,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                    ),
                  ),
                ),
            ],
          ),
        ),
      ),
    );
  }
}
